#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "unistd.h"
#include "signal.h"
#include "sys/time.h"
static int i = 0;


void hello()
{
    i++;
    printf("i am run!\r\n");
}
int main(){
    struct itimerval st;
    signal(SIGALRM,hello);
    st.it_value.tv_sec=3;
    st.it_value.tv_usec=0;
    st.it_interval.tv_sec=1;
    st.it_interval.tv_usec=0; 
    setitimer(ITIMER_REAL,&st,NULL);
    while(1){
        if(i==10){
            i++;
            st.it_value.tv_sec=0;
            st.it_value.tv_usec=0;
            st.it_interval.tv_sec=0;
            st.it_interval.tv_usec=0; 
            //A timer which is set to zero (it_value is zero or the timer expires and it_interval is zero) stops.
            setitimer(ITIMER_REAL,&st,NULL);
            break;
        }
    }
    sleep(5);
    return 0;
}